package com.example.mylibrarybase.yumengmeng20.ui;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.mylibrarybase.R;
import com.example.mylibrarybase.bar.initAction_Bar;
import com.example.mylibrarybase.base.baseui.BaseActivity;
import com.example.mylibrarybase.utils.UtilsToast;
import com.example.mylibrarybase.yumengmeng20.utils.Utilssocket;

public class MainActivity_20_socket extends BaseActivity implements View.OnClickListener {

    private initAction_Bar mBase_action_bar;
    private TextView mTv_client;
    private TextView tv_serven;
    private TextView tv_status;
    private EditText ed_input_ip;
    private EditText ed_input_port;
    private EditText tv_manseeger;
    private TextView tv_send__manseeger;
    private TextView mGetloction_ip;
    Handler mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
           switch (msg.what){
               case 11:

               break;
           }
            Bundle data = msg.getData();
            String string = data.getString("2", "0");
            UtilsToast.showToast(MainActivity_20_socket.this, string);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    @Override
    public int getlayouXML() {
        return R.layout.activity_main_20_socket;
    }

    @Override
    public void initView() {
        mBase_action_bar = (initAction_Bar) findViewById(R.id.base_action_bar);
        mBase_action_bar.setCallBack(new initAction_Bar.Action_bar_call_back() {
            @Override
            public void getAction_barView_backbutton(TextView textView) {

            }

            @Override
            public void getAction_barView_backbutton_icon(ImageView imageView) {

            }

            @Override
            public void getAction_barView_title(TextView textView) {
                textView.setText("socket通讯");
            }

            @Override
            public void getAction_barView_right_icon(ImageView imageView) {

            }
        });
        mTv_client = (TextView) findViewById(R.id.tv_client);
        tv_serven = (TextView) findViewById(R.id.tv_serven);
        tv_status = (TextView) findViewById(R.id.tv_status);
        tv_send__manseeger = (TextView) findViewById(R.id.tv_send__manseeger);

        ed_input_ip = (EditText) findViewById(R.id.ed_input_ip);
        ed_input_port = (EditText) findViewById(R.id.ed_input_port);
        tv_manseeger = (EditText) findViewById(R.id.tv_manseeger);


        mGetloction_ip = (TextView) findViewById(R.id.getloction_ip);
       Utilssocket.getIP(this, mGetloction_ip);
      //  String s = Utilssocket.intToIp(Integer.parseInt(localIpAddress));
       // mGetloction_ip.setText(localIpAddress);
        mTv_client.setOnClickListener(this);
        tv_serven.setOnClickListener(this);
        tv_send__manseeger.setOnClickListener(this);

       // tv_serven.setText(localIpAddress);
        initData();
    }

    @Override
    public void initData() {

    }

    @Override
    public void onClick(View view) {
        int i = view.getId();
        if (i == R.id.tv_client) {

            String s = ed_input_ip.getText().toString();
            String s1 = ed_input_port.getText().toString();
            String s2 = tv_manseeger.getText().toString();
            Utilssocket.getSocket(this,mHandler)
                    .connectServerWithTCPSocket(s,s1,s2);



            //   Utilssocket.connectServerWithTCPSocket(this, s,s1,s2);

        } else if (i == R.id.tv_serven) {
            String s1 = ed_input_port.getText().toString();
           // String localIpAddress = Utilssocket.getLocalIpAddress();
          //  Utilssocket.ServerReceviedByTcp(this,s1);
            Utilssocket.getSocket(this,mHandler).ServerReceviedByTcp(s1);
        } else if (i == R.id.tv_send__manseeger) {

        }
    }


}
